package pro.huadi.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pro.huadi.mapper.BookMapper;
import pro.huadi.pojo.Book;

import pro.huadi.pojo.User;
import pro.huadi.util.Result;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping
public class BookController {
    @Autowired
    BookMapper bookMapper;

    @PostMapping(value = {"/query"},produces = {"application/json; charset=UTF-8"})
    public Result query(){
        //System.out.println(bookMapper.queryAll());
        return Result.ok().data("books",bookMapper.queryAll());
    }

    //增删改后保存变化到数据库中
    @PostMapping(value = {"/saveChange"},produces = {"application/json; charset=UTF-8"})
    public void saveChange(@RequestBody List<Book> books){

//        //删掉
        bookMapper.delete();
       System.out.println(books);
//        //添加
        for (Book book : books) {
            System.out.println(book);
            bookMapper.add(book);
        }

    }


}
